// 先渲染用户信息
$(function () {
  const getUserInfo = async () => {
    const res = await reqUserInfoGet()
    console.log(res)
    let { id, email, nickname, username } = res.data
    $('input[name=username]').val(username)
    $('input[name=nickname]').val(nickname)
    $('input[name=email]').val(email)
		$('input[name=id]').val(id)
  }
  getUserInfo()
	
	// 点击修改时验证+请求
	$('.layui-form').on('submit', async e => {
		e.preventDefault()
		const data = {
			id: $('input[name=id]').val(),
			nickname: $('input[name=nickname]').val(),
			email: $('input[name=email]').val()
		}
		const dataStr = handleDataFormat(data)
		const res = await reqUpdateUserInfoPost(dataStr)
		console.log(res)
		const {message} = res
		layer.msg(message, { time: 1500, icon: 1 })
		// 更新小页面外面的信息
		window.parent.getUserInfo()
	})
	// 重置功能
	$('button[type=reset]').on('click', e => {
		e.preventDefault()
		// 重置的时候不需要清空和刷新表单
		getUserInfo()
	})



})
